package com.cmcc.aregister.ui.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cmcc.aregister.R;
import com.cmcc.aregister.cs.model.Schedule;

public class ChoiceTimeAdapter extends BaseAdapter {
    private Context context = null;
    public List<Schedule> list = null;
    private String schedule_info;

    public ChoiceTimeAdapter(Context context, List<Schedule> list,
        String schedule_info) {
        this.context = context;
        this.list = list;
        this.schedule_info = schedule_info;
    }

    public int getCount() {
        return list.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(
                R.layout.a_choice_time, null);
            holder.name = (TextView) convertView.findViewById(R.id.name);
            holder.time = (TextView) convertView.findViewById(R.id.time);
            holder.yuyue_num = (TextView) convertView
                .findViewById(R.id.yuyue_num);
            holder.left_num = (TextView) convertView
                .findViewById(R.id.left_num);
            convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
        }
        Schedule schedule = list.get(position);
        String temp[] = schedule_info.split(" ");
        String name = temp[0];
        String time = temp[1];
        holder.name.setText(name);
        holder.time.setText(time + "  " + context.getString(R.string.left_num));
        holder.yuyue_num.setText(schedule.left_num);
        holder.left_num
            .setText(schedule.begin_time + " - " + schedule.end_time);

        return convertView;
    }

    static class ViewHolder {
        TextView name, time, left_num, yuyue_num;

    }
}